<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"
%>
<%@ page import="com.resource.allocator.model.Resource,com.resource.allocator.model.*, 
java.util.List,com.resource.allocator.EMF,javax.persistence.*, 
com.google.appengine.api.datastore.KeyFactory"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link type="text/css" href="/css/bootstrap.css" rel="stylesheet" />
<title>Resource modify</title>
</head>
<body>
    <%
        Resource r = (Resource) request.getAttribute("aResource");
        String formAction = (r!=null && r.getKey() != null ? "edit" : "create");
    %>
    <div class="container">
    <pre><h3><%= formAction %></h3></pre>
    <form class="well" action="/resourcesController" method="post">
        <input type="hidden" name="action" value="<%= formAction %>" />
             
        <input type="hidden" name="key" value="<%=(r.getKey() != null ? KeyFactory.keyToString(r.getKey()) : "")%>" /> 
        <label for="firstName">Firstname</label>
        <input type="text" name="firstName" id="firstName" value="<%=r.getFirstName()!=null?r.getFirstName():"" %>" /> 
        <label for="lastName">Lastname</label>
        <input type="text" name="lastName" id="lastName" value="<%=r.getLastName()!=null?r.getLastName():"" %>" /> 
        <label for="capacity">Capacity</label> 
        <input class="span1" type="text" name="capacity" id="capacity" 
        value="<%=(r!=null && r.getCapacity() != null ? r.getCapacity() : "")%>" />
        <div class="control-group">
            <label for="skillList">Skills</label>
            <a href="/resourcesController?action=addskill"><i class="icon-plus"></i>create skill</a>
            <div class="control">
            <%
                EntityManager em = EMF.get().createEntityManager();
        	    try{
        	        Query q = em.createQuery("select s from Skill s order by s.name");
        	        List<Skill> list = q.getResultList();
        	        for(Skill s:list){                    
            %>
                <label class="checkbox">
                <input type="checkbox" name="skill" value="<%= KeyFactory.keyToString(s.getKey()) %>" />
                <%= s.getName() %>
                </label> 
            <%
        	       }
        	    }finally{
                   em.close();
                }
            %>
            </div>
        </div>
        <%-- 
        <label for="firstName">Firstname</label> 
        <input type="text" name="firstName" id="firstName"/> 
        <label for="lastName">Lastname</label> 
        <input type="text" name="lastName" id="lastName" /> 
        <label for="capacity">Capacity</label> 
        <input class="span1" type="text" name="capacity" id="capacity" />
        <div class="control-group">
            <label for="skillList">Skills</label>
            <div class="control">
                <label class="checkbox"><input type="checkbox" name="skills" value="1" />Java</label> 
                <label class="checkbox"><input type="checkbox" name="skills" value="2" />.Net</label> 
                <label class="checkbox"><input type="checkbox" name="skills" value="3" />Javascript</label> 
                <label class="checkbox"><input type="checkbox" name="skills" value="4" />HTML & CSS</label>
            </div>
        </div>
        --%>
        <input type="submit" class="btn" value="Save" /> <input type="reset" class="btn" />
    </form>
</div>
</body>
</html>